package com.ruoyi.fly.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.fly.domain.ChlLbt;
import com.ruoyi.fly.domain.vo.ChlLbtSearchVo;
import com.ruoyi.fly.domain.vo.ChlLbtVo;
import com.ruoyi.fly.domain.vo.DeleteVo;
import com.ruoyi.fly.service.ChlLbtService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/chlLbt")
@Api(tags = "轮播图管理")
public class ChlLbtController extends BaseController {

    @Autowired
    private ChlLbtService chlLbtService;

    /**
     * 查询轮播图列表
     */
    @ApiOperation(value = "查询轮播图列表", notes = "查询轮播图列表")
    @PostMapping(value = "/selectList")
    public TableDataInfo list(@RequestBody ChlLbtSearchVo chlLbtSearchVo) {
        PageDomain pageDomain = new PageDomain();
        BeanUtils.copyProperties(chlLbtSearchVo,pageDomain);
        startPage(pageDomain);
        return getDataTable(chlLbtService.selectLbtList(chlLbtSearchVo));
    }

    /**
     * 根据id查询轮播图
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询轮播图", notes = "根据id查询轮播图")
    @GetMapping(value = "/selectById/{id}")
    public R selectById(@PathVariable("id") String id) {
        if (id == null) {
            return R.fail("参数不能为空");
        }
        if (chlLbtService.selectLbtById(id) == null) {
            return R.fail("数据不存在");
        }
        return R.ok(chlLbtService.selectLbtById(id));
    }

    @ApiOperation(value = "后台添加轮播图", notes = "后台添加轮播图")
    @PostMapping(value = "/addlbt")
    public R addlbt(@RequestBody ChlLbt chlLbt) {
        if (StringUtils.isBlank(chlLbt.getImg())) {
            return R.fail("参数不能为空");
        }
        return chlLbtService.addlbt(chlLbt);
    }

    @ApiOperation("修改")
    @PostMapping(value = "/editLbt")
    public R editLbt(@RequestBody ChlLbt chlLbt) {
        if (StringUtils.isBlank(chlLbt.getImg())) {
            return R.fail("参数不能为空");
        }
        return chlLbtService.editLbt(chlLbt);
    }

    @ApiOperation(value = "后台删除轮播图", notes = "后台删除轮播图")
    @PostMapping(value = "/deletelbt")
    public R deletelbt(@RequestBody DeleteVo deleteVo) {
        if (StringUtils.isEmpty(deleteVo.getIds())) {
            return R.fail("参数不能为空");
        }
        return chlLbtService.deleteLbtByIds(deleteVo.getIds());
    }
}
